package blackbirdisoserver;

import org.jdom.Element;
import org.jdom.Comment;
import org.jpos.iso.ISOUtil;
import org.jpos.q2.Q2;
import org.jpos.q2.QBean;
import org.jpos.q2.QBeanSupport;

import org.jpos.util.Log;
import org.jpos.util.Logger;

public class QTest extends QBeanSupport implements Runnable, QTestMBean
{
	public static void main(String[] args)
	{
		QTest foo = new QTest(9000);
		foo.start();
		
	}
	long tickInterval = 1000;
	int port;

	public QTest(int portNumber)
	{
		super();
		port = portNumber;
		log.info("constructor");
	}

	public void init()
	{
		log.info("init");
		super.init();
	}

	public void start()
	{
		log.info("start");
		super.start();
	}

	public void stop()
	{
		log.info("stop");
		super.stop();
	}

	public void destroy()
	{
		log.info("destroy");
		log = null;
	}

	public void setPersist(Element e)
	{
		log.info("setPersist");
		super.setPersist(e);
	}

	public Element getPersist()
	{
		setModified(false);
		log.info("getPersist");
		return createElement("qtest", QTestMBean.class);
	}

	public void setName(String name)
	{
		log.info("setName " + name);
		super.setName(name);
	}

	public void setTickInterval(long tickInterval)
	{
		this.tickInterval = tickInterval;
		setModified(true);
	}

	public long getTickInterval()
	{
		return tickInterval;
	}

	public void run()
	{
		for(int tickCount=0; running(); tickCount++)
		{
			log.info("tick " + tickCount);
			ISOUtil.sleep(tickInterval);
		}
	}

	public void startServivce()
	{
		new Thread(this).start();
	}

	@Override
	public int getPort()
	{
		// TODO Auto-generated method stub
		return 0;
		
	}

	@Override
	public void setPort(int portNumber)
	{
		port = portNumber;
		// TODO Auto-generated method stub
	}
}
